<template>
    <el-card class="script-card" shadow="hover" :body-style="{ padding: '0px' }">
        <div class="script-image-container">
            <el-image
                    :src="script.cover"
                    fit="cover"
                    class="script-image"
            >
                <template #error>
                    <div class="image-error">
                        <el-icon><Picture /></el-icon>
                    </div>
                </template>
            </el-image>
            <div class="script-difficulty">
                难度: {{ getDifficultyText(script.difficulty) }}
            </div>
        </div>

        <div class="script-info">
            <h3 class="script-title">{{ script.title }}</h3>

            <div class="script-meta">
        <span class="script-players">
          <el-icon><User /></el-icon>
          {{ script.minPlayers }}-{{ script.maxPlayers }}人
        </span>
                <span class="script-duration">
          <el-icon><Clock /></el-icon>
          {{ script.duration }}小时
        </span>
            </div>

            <div class="script-genres">
                <el-tag
                        v-for="genre in script.genres.slice(0, 2)"
                        :key="genre"
                        size="small"
                        :type="genre === '恐怖' ? 'danger' : genre === '情感' ? 'success' : ''"
                >
                    {{ genre }}
                </el-tag>
                <el-tag v-if="script.genres.length > 2" size="small" type="info">
                    +{{ script.genres.length - 2 }}
                </el-tag>
            </div>

            <div class="script-desc">
                {{ script.description.substring(0, 50) }}{{ script.description.length > 50 ? '...' : '' }}
            </div>

            <div class="script-shops">
                提供商家: {{ script.availableShops.length }}家
            </div>
        </div>
    </el-card>
</template>

<script setup>
import { Picture, User, Clock } from '@element-plus/icons-vue'

const props = defineProps({
    script: {
        type: Object,
        required: true
    }
})

const getDifficultyText = (difficulty) => {
    const levels = ['简单', '中等', '困难', '烧脑']
    return levels[difficulty - 1] || levels[0]
}
</script>

<style scoped>
.script-card {
    cursor: pointer;
    transition: transform 0.3s;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.script-card:hover {
    transform: translateY(-5px);
}

.script-image-container {
    position: relative;
    height: 180px;
    overflow: hidden;
}

.script-image {
    width: 100%;
    height: 100%;
}

.image-error {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    color: #999;
}

.script-difficulty {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.script-info {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.script-title {
    margin: 0 0 10px 0;
    font-size: 16px;
    font-weight: bold;
}

.script-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: #666;
    font-size: 13px;
}

.script-genres {
    margin-bottom: 10px;
}

.script-genres .el-tag {
    margin-right: 5px;
    margin-bottom: 5px;
}

.script-desc {
    color: #666;
    font-size: 13px;
    line-height: 1.5;
    margin: 10px 0;
}

.script-shops {
    font-size: 12px;
    color: #999;
    margin-top: auto;
}
</style>